package com.cnswhy.cloud.server.core.dao;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.cnswhy.cloud.common.core.base.mapper.SuperMapper;
import com.cnswhy.cloud.server.core.dto.CustomerWalletTransDtlPageDTO;
import com.cnswhy.cloud.server.core.dto.SpellOrderDetailPageDTO;
import com.cnswhy.cloud.server.core.entity.CustomerWalletTransDtl;
import com.cnswhy.cloud.server.core.entity.SpellOrder;
import com.cnswhy.cloud.server.core.entity.SpellOrderDetail;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.math.BigDecimal;
import java.util.List;

/**
 * <p>
 * Mapper 接口
 * 
 * </p>
 *
 * @author cnswhy
 * @date 2020-10-16
 */
@Repository
public interface SpellOrderMapper extends SuperMapper<SpellOrder> {
    int queryCustomerSpellOrder(SpellOrder bo);
    @Select("select ifnull(sum(t.order_price),0) from t_spell_order t where t.status= 3 and t.sett_date = #{settDate}")
    BigDecimal querySpellSuccessMoney(@Param("settDate") String settDate);
    @Select("select ifnull(sum(t.order_price),0) from t_spell_order t where t.status= 3  and product_id in (select id from t_shop_product where spell_product = 1) and t.sett_date = #{settDate}")
    BigDecimal querySpellSuccessMoneyAndSpellProduct(@Param("settDate") String settDate);
    @Select("select * from t_spell_order where spell_order_id = #{spellOrderId} and status = #{status} order by create_time")
    List<SpellOrder> getSpellingOrder(@Param("spellOrderId") String spellOrderId, @Param("status") Integer status);
    @Select("select ifnull(sum(t.order_price),0) from t_spell_order t where t.goods_type is null and t.status = 3")
    BigDecimal getUndealSumAmount();
    @Select("select * from t_spell_order where spell_order_id = #{spellOrderId} and send_status = #{status} order by create_time")
    List<SpellOrder> getSpellingOrderBySendStatus(@Param("spellOrderId") String spellOrderId, @Param("status") Integer status);
    @Select("select * from t_spell_order where spell_order_id = #{spellOrderId} and status = #{status} and is_privilege = 2 order by create_time")
    List<SpellOrder> getSpellingOrderIsPrivilege(@Param("spellOrderId") String spellOrderId, @Param("status") Integer status);
    @Select("update t_spell_order set spell_order_id = #{newSpellOrderId} where spell_order_id = #{spellOrderId} and status in (1, 2)")
    void updateNewSpellOrderId(@Param("spellOrderId") String spellOrderId, @Param("newSpellOrderId") String newSpellOrderId);

    IPage<SpellOrderDetail> getSendList(IPage page, @Param("data") SpellOrderDetailPageDTO spellOrderDetailPageDTO);
    IPage<SpellOrderDetail> getSpellList(IPage page, @Param("data") SpellOrderDetailPageDTO spellOrderDetailPageDTO);
    List<SpellOrderDetail> exportSpellList(@Param("data") SpellOrderDetailPageDTO spellOrderDetailPageDTO);



}
